'直线移动组件，给定位置，朝位置移动'

extends Node

@export var max_speed: int = 50
@export var acceleration : float = 5

var velocity = Vector2.ZERO


func move(body: CharacterBody2D, target_position: Vector2) -> void:
	var owner_node2d = self.owner as Node2D
	if owner_node2d == null:
		return
	var direction = (target_position - owner_node2d.global_position).normalized()
	var direction_velocity = direction * max_speed
	body.velocity = body.velocity.lerp(direction_velocity, 1 - exp(-acceleration * get_process_delta_time()))
	
	body.move_and_slide()
	#velocity = body.velocity
	pass
